<template>
  <div class="mod-config">
    <el-form
      :model="dataForm"
      :rules="dataRule"
      ref="dataForm"
      label-width="120px"
    >
      <el-form-item label="输入旧密码" prop="oldPassword">
        <el-input
          style="width: 250px"
          v-model="dataForm.oldPassword"
          placeholder="请输入"
        ></el-input>
      </el-form-item>
      <el-form-item label="输入新密码" prop="newPassword">
        <el-input
          style="width: 250px"
          v-model="dataForm.newPassword"
          placeholder="请输入"
        ></el-input>
      </el-form-item>
      <el-form-item label="再次输入密码" prop="confirmPassword">
        <el-input
          style="width: 250px"
          v-model="dataForm.confirmPassword"
          placeholder="请输入"
        ></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <!-- <el-button @click="visible = false">取消</el-button> -->
      <el-button
        type="primary"
        @click="dataFormSubmit()"
        style="margin-left: 30px"
        >保存</el-button
      >
    </span>
  </div>
</template>

<script>
import md5 from "js-md5";
export default {
  data() {
    var validateConfirmPassword = (rule, value, callback) => {
      if (this.dataForm.newPassword !== value) {
        callback(new Error("确认密码与新密码不一致"));
      } else {
        callback();
      }
    };
    return {
      isdisabled:false,
      dataForm: {
        oldPassword: "",
        newPassword: "",
        confirmPassword: "",
      },
      dataRule: {
        oldPassword: [
          { required: true, message: "请输入旧密码", trigger: "blur" },
        ],
        newPassword: [
          { required: true, message: "请输入新密码", trigger: "blur" },
        ],
        confirmPassword: [
          { required: true, message: "确认密码不能为空", trigger: "blur" },
          { validator: validateConfirmPassword, trigger: "blur" },
        ],
      },
    };
  },
  components: {},
  activated() {},
  methods: {
    // 获取数据列表
    dataFormSubmit() {
      this.$refs["dataForm"].validate((valid) => {
        if (valid) {
          this.isdisabled=true
          this.$http({
            url: this.$http.adornUrl(`/admin/user/updateSysUserPassword`),
            method: "put",
            data: this.$http.adornData({
              password: md5(this.dataForm.oldPassword).toLowerCase(),
              newPassword: md5(this.dataForm.newPassword).toLowerCase(),
            }),
          }).then(({ data }) => {
            if (data && data.code === "200") {
              this.$router.replace({ name: "login" });
              this.isdisabled=false
            } else {
              this.isdisabled=false
            }
          });
        }
      });
    },
    // 每页数
  },
};
</script>
